package com.apes.scm.masterdata.enumeration.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：枚举
 *
 * @author xul
 * @create 2018-03-05 11:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = Enumeration.CONST_TABLE_NAME, indexes = {
        @Index(name = "IDX_MAS_ENUMERATION_TYPE_DESC", columnList = "enumeration_type_id, description", unique = true)
})
public class Enumeration extends BaseModel {
    public static final String CONST_TABLE_NAME = "mas_enumeration";

    @Id
    @Column(name = "id", length = 30 )
    @ApesGenerator(code = CONST_TABLE_NAME, name = "枚举表")
    @Comment("编码")
    private String id;  //编码

    @ManyToOne(optional = false)
    @JoinColumn(name = "enumeration_type_id", referencedColumnName = "id", nullable = true)
    @Comment("枚举类型")
    private EnumerationType type; //枚举类型

    @Name
    @Column(name = "code", length = 120)
    @Comment("显示编码")
    private String code;  //显示编码

    @Name
    @Column(name = "description", length = 120, nullable = false)
    @Comment("描述")
    private String description;  //描述

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效")
    private boolean valid; //有效

    @Name
    @Column(name = "remark", length = 120)
    @Comment("备注")
    private String remark;


}
